<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta http-equiv="pragram" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>[title]</title>
    <link href="/Public/Home/css/style.css" rel="stylesheet" type="text/css">
    <link href="/Public/Home/css/iconfont.css" rel="stylesheet" type="text/css">
    <script src="/Public/Home/js/jquery-1.11.1.min.js"></script>
    <script src="/Public/Home/js/publicjquery.js"></script>
    <script src="/Public/Home/js/layer/layer.js" ></script>
    <script src="/Public/Home/js/common.js" ></script>
    <script src="/Public/Home/js/ajaxfileupload.js" ></script>
</head>
<body onselectstart="return false">
<div class="main FromUpToDown" >
    <div class="content" style="position: relative">
        <div class="head-content">
            <div class="head-title">
                <span><?php echo ACTION_NAME == 'edit' ? '修改' : '添加';?>用户</span>
            </div>
        </div>
        <form action='' id="form" >
            <div class="form-content">
                <div class="form">
                    <div class="form-left">手机号</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='phone'  value="<?php echo ($info['phone']); ?>" placeholder="手机号"  />
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">客户名</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='name'  value="<?php echo ($info['name']); ?>" placeholder="用户名"  />
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">价格模板</div>
                    <div class="form-right">
                        <select name="template_name"  class="form-input-small" >
                        <option value="">请选择价格模板</option>
                            <?php if(is_array($template_name)): foreach($template_name as $key=>$vo): ?><option <?php echo $vo['name'] == $info['template_name'] ? 'selected' : '';?>  value="<?php echo ($vo['name']); ?>"><?php echo ($vo['name']); ?></option><?php endforeach; endif; ?> 
                        </select>
                    </div>
                </div>
                  <div class="form">
                    <div class="form-left">身份证正面</div>
                    <div class="form-right">
                        <label style="height:200px;max-width: 200px">
                            <?php if(!$info['card']): ?><img style="height: 50px;max-width: 50px" id="image_show2" src="/Public/Home/images/add.png" alt="身份证照片" >
                                <?php else: ?>
                                <img style="height: 150px;max-width: 200px" id="image_show2" src="<?php echo ($info['card']); ?>" alt="身份证照片" ><?php endif; ?>
                        <input type="file" style="display: none" id="upload2" name="photo" onchange="ajaxFileUpload2()" >
                        <input type="hidden" id="card" name="card" value="<?php echo ($info['card']); ?>" >
                        </label>
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">身份证反面</div>
                    <div class="form-right">
                        <label style="height:200px;max-width: 200px">
                            <?php if(!$info['card_image']): ?><img style="height: 50px;max-width: 50px" id="image_show" src="/Public/Home/images/add.png" alt="身份证照片" >
                                <?php else: ?>
                                <img style="height: 150px;max-width: 200px" id="image_show" src="<?php echo ($info['card_image']); ?>" alt="身份证照片" ><?php endif; ?>
                        <input type="file" style="display: none" id="upload" name="photo" onchange="ajaxFileUpload()" >
                        <input type="hidden" id="card_image" name="card_image" value="<?php echo ($info['card_image']); ?>" >
                        </label>
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">地址</div>
                    <div class="form-right">
                        <input class="form-input-small" type="text" name='addr'  value="<?php echo ($info['addr']); ?>" placeholder="地址"  />
                    </div>
                </div>
                <div class="form">
                    <div class="form-left">备注</div>
                    <div class="form-right">
                        <textarea name="remark"  cols="30" rows="5"><?php echo ($info['remark']); ?></textarea>
                    </div>
                </div>
                <input type='hidden' name='id' value="<?php echo ($info['id']); ?>" >
                <div class="form-operate">
                    <button type='button' id="save"  class="form-button color-bg-green">保存</button>
                    <button type='button' onclick="history.go(-1)" class="form-button color-bg-grey">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="main-foot">Copyright  2013-2015 WeiGouTong.com. All Rights Reserved.  苏ICP备09098830号</div>
<script>
    //上传图片
    function ajaxFileUpload() {
        $.ajaxFileUpload
        (
                {
                    url: "<?php echo U('Tool/upload');?>", //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'upload', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data, status)  //服务器成功响应处理函数
                    {
                        if(data.status == 1){
                            $("#image_show").attr('src',data.info);
                            $("#card_image").val(data.info);
                        }else{
                            layer.msg(data.info,{time:1000});
                        }
                    }
                }
        )
        return false;
    }
	
	 function ajaxFileUpload2() {
        $.ajaxFileUpload
        (
                {
                    url: "<?php echo U('Tool/upload');?>", //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'upload2', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data, status)  //服务器成功响应处理函数
                    {
                        if(data.status == 1){
                            $("#image_show2").attr('src',data.info);
                            $("#card").val(data.info);
                        }else{
                            layer.msg(data.info,{time:1000});
                        }
                    }
                }
        )
        return false;
    }

    $("#save").click(function(){

        if($("input[name='name']").val() == ''){
            layer.tips('请输入客户名！', 'input[name="name"]', {tips: [2, 'red'], time: 1000});
            return;
        }
        var reg = /1[3578]\d{9}/;
        if(!reg.test($("input[name='phone']").val())){
            layer.tips('请填写合理手机号！', 'input[name="phone"]', {tips: [2, 'red'], time: 1000});
            return;
        }
        $("#save").attr('disabled',true);
        $.post(
                "<?php echo U('save');?>",
                $("#form").serialize(),
                function(res){
                    if(res.status == 1){
                        layer.tips(res.info, '#save', {tips: [2, 'green'], time: 1000});
                        setTimeout("location.href = document.referrer",1000);
                    }else{
                        layer.tips(res.info, '#save', {tips: [2, 'red'], time: 1000});
                        $("#save").attr('disabled',false);
                    }
                }
        );
    });

     $("input[name='phone']").bind("input propertychange",function(){
            var reg = /^1[34578]\d{9}$/;
            var phone = $(this).val();
            if(reg.test($(this).val())){
                $.post(
                        "<?php echo U('Customer/getCustomer');?>",
                        {
                            phone:phone
                        },function(res){
                           if(res.status == 1){
                               $("input[name='name']").val(res.info['name']);
                               $("input[name='addr']").val(res.info['addr']);
                               if(res.info['card']){
                                    $("#image_show2").attr('src',res.info['card']);
                               }
                               if(res.info['card_image']){
                                    $("#image_show").attr('src',res.info['card_image']);
                               }
                               $("textarea[name='remark']").val(res.info['remark']);
                           }
                        }
                );
            }
    })

</script>
</body>
</html>